//
//  MatchVC.m
//  Match
//
//  Created by lanou3g on 15/6/1.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "MatchVC.h"
#import "UMSocial.h"
#import "WebGetData.h"
#import "DatabaseHandle.h"
@interface MatchVC ()<UIWebViewDelegate>

@end

@implementation MatchVC

- (void)setModel:(NewsModel *)model{
    if (_model!=model) {
        _model =model;
    }
#pragma ---设置视图内容---

    [WebGetData setMatchView:self withModel:model];
      
}





-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.view.backgroundColor = [UIColor grayColor];
    
    self.webView.delegate =self;
    __weak typeof(self) weakSelf = self;
    [WebGetData getStringWithUrlString:[NSString stringWithFormat:@"%@%@",self.detailWeb,self.model.gid] success:^(NSString *content) {
    
        [weakSelf.webView loadHTMLString:content baseURL:nil];

    }];
}


#pragma ---webView的delegate实现---
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    
    
    [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"WebKitCacheModelPreferenceKey"];
    [[NSUserDefaults standardUserDefaults] synchronize];
   
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setBarButtonItems];
     // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)setBarButtonItems{
    
    UIBarButtonItem *leftBackItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(didClickBack)];
    leftBackItem.tintColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem =leftBackItem;
    
    UIBarButtonItem *rightFavorite = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"Favorite"] style:UIBarButtonItemStylePlain target:self action:@selector(favorite)];
    rightFavorite.tintColor = [UIColor whiteColor];
    UIBarButtonItem *rightShare  = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(share )];
    rightShare.tintColor = [UIColor whiteColor];
    self.navigationItem.rightBarButtonItems = @[rightShare,rightFavorite];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
}

- (void)didClickBack{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)favorite{
    
   DatabaseHandle *handle =[DatabaseHandle shardInstnce];
   
   handle.fileName = @"match.sqlite3";
   handle.viewController = self;
   
    if (![handle isFavoriteModelWithID:self.model.ID]) {
      
        [handle insertNewactivity:self.model];
 
    }
}



- (void)share{
    [UMSocialSnsService presentSnsIconSheetView:self appKey:@"55724dc967e58ee8ca002061" shareText:[NSString stringWithFormat:@"%@%@",self.detailWeb,self.model.gid]  shareImage:nil shareToSnsNames:[NSArray arrayWithObjects:UMShareToDouban,UMShareToRenren,UMShareToSina,UMShareToEmail,UMShareToFacebook,UMShareToKakaoTalk,UMShareToFlickr, nil] delegate:nil];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
